<table class="am-table am-table-bordered am-table-striped charge_stat">
    <thead>
        <tr>
            <th class="t">充值方式</th>
            <th>手工存款</th>
            <th>银行转账</th>
            <th>微信转账</th>
            <th>支付宝转账</th>
            <th>第三方支付</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<div id="c_charge_stat" style="margin: 10px 0px 10px 10px; width: 680px; height: 300px;">
</div>

<script>
    function fillChargeStat() {
        var table = $(".charge_stat tbody");
        table.empty();
        var day = datas.length > 3;
        
        for (var i = 0; i < datas.length; i++) {
            var d = datas[i].deposit || {};
            tr = $("<tr></tr>");
            if (day) {
                if (i == 0) tr.append("<td>今天</td>");
                else if (i == 1) tr.append("<td>昨天</td>");
                else if (i == 2) tr.append("<td>前天</td>");
                else tr.append("<td>" + (i + 1) + "天前</td>");
            }
            else {
                if (i == 0) tr.append("<td>本月</td>");
                else if (i == 1) tr.append("<td>上月</td>");
                else if (i == 2) tr.append("<td>上上月</td>");
                else continue;
            }
            
            tr.append("<td>" + (((d.manual || 0)/100).toFixed(2)) + "</td>");
            tr.append("<td>" + (((d.bank || 0)/100).toFixed(2)) + "</td>");
            tr.append("<td>" + (((d.wechat || 0)/100).toFixed(2)) + "</td>");
            tr.append("<td>" + (((d.alipay || 0)/100).toFixed(2)) + "</td>");
            tr.append("<td>" + (((d.third || 0)/100).toFixed(2)) + "</td>");
            table.append(tr);
        }

        // 图表
        var series = [];
        var f = function(title, cb) {
            var data = {
                name: title,
                type: 'line',
                stack: '总额',
                data: [],
            }
            for (var i = datas.length - 1; i >= 0; i--) {
                var d = datas[i].deposit || {};
                data.data.push(cb(d));
            }
            series.push(data);
        }
        f('手工存款', function(d) {
            return (d.manual || 0)/100;
        });
        f('银行转账', function(d) {
            return (d.bank || 0)/100;
        });
        f('微信转账', function(d) {
            return (d.wechat || 0)/100;
        });
        f('支付宝转账', function(d) {
            return (d.alipay || 0)/100;
        });
        f('第三方支付', function(d) {
            return (d.third || 0)/100;
        });

        var c = echarts.init($("#c_charge_stat")[0]);
        var option = {
            title: {
                text: "用户数据",
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['手工存款', '银行转账', '微信转账', '支付宝转账', '第三方支付'],
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: day ? ['6天前', '5天前', '4天前', '3天前', '前天', '昨天', '今天'] : ['上上月', '上月', '本月'],
            },
            yAxis: {
                type: 'value',
            },
            series: series,
        };
        c.setOption(option)
    }
    fillChargeStat();

    $("#popup-page").click(function() {
        $("#charge_stat").remove();
    });
    $(".am-table").click(function(e) {
        e.stopPropagation();
    });
</script>